.\"
.\" UCSD p-System cross compiler
.\" Copyright (C) 2011, 2012 Peter Miller
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation; either version 2 of the License, or (at
.\" you option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
.\" General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License along
.\" with this program. If not, see
Up, Prev | Next |
\&... imperative type-based dispatch | \&... facility of the C++ language |
expression : expression ASSIGN expression { $$ = context->expression_assignment($1, $3); } ; |
expression : expression ASSIGN expression { $$ = $1->expression_assignment($3); } ; |
void translator::expression_assignment(expression *lhs, expression *rhs) { |
class expression { public: virtual expression *assignment_expression(expression *rhs); }; |
expression_ldl *t1 = dynamic_cast<expression_ldo>(lhs) if (t1) return new expression_sro(t1->get_address(), rhs); |
expression * expression_ldo::assignment_factory(expression *rhs) { return new expression_sro(address, rhs); } |
etc etc etc | etc etc etc |
yyerror("left hand side of assignment inappropriate"); return new expression_error(); } |
expression * expression::assignment_factory(expression *) { yyerror("left hand side of assignment inappropriate"); return new expression_error(); } |
Now you have a translator class that can manufacture an expression class
that can manufacture another expression class.
You have a factory factory. |
![]() |